<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>QQ浏览器分享</title>
  <link rel="stylesheet" type="text/css" href="/assets/css/bootstrap.min.css">
</head>

<body>
  <div class="container">
    <div class="col-12 col-md-6">
    <div class="form-group">
      <label>标题：</label>
      <input type="text" name="title" id="title" class="form-control" />
    </div>
    <div class="form-group">
      <label>描述：</label>
      <input type="text" class="form-control" id="description" />
    </div>
    <div class="form-group">
      <label>图片地址：</label>
      <input type="text" class="form-control" id="img_url" />
    </div>
    @if ($data['type'])
    <div class="form-group">
      <label for="url">要分享的链接</label>
      <select multiple class="form-control" id="url">
        @foreach ($data['urls'] as $url)
        <option value="{{ $url }}">{{$url}}</option>
        @endforeach
      </select>
    </div>
    @endif
    <button class="btn btn-primary" onclick="shareFriend()">分享朋友</button>
    <button class="btn btn-primary" onclick="shareTimeline()">分享朋友圈</button>
    <a href="/" class="ml-3">返回</a>
  </div>
  </div>

  <script>
  window.onload = function() {

    var UA = navigator.appVersion;
    var qq = UA.split('MQQBrowser/').length > 1 ? 2 : 0;
    var qqVs = qq ? parseFloat(UA.split('MQQBrowser/')[1]) : 0;

    var os = (function() {
      var ua = navigator.userAgent;

      if (/iphone|ipod/i.test(ua)) {
        return 1;
      } else if (/android/i.test(ua)) {
        return 2;
      } else {
        return 0;
      }
    }());

    if ((qq && qqVs < 5.4 && os == 1) || (qq && qqVs < 5.3 && os == 1)) {
      qq = 0;
    } else {
      if (qq && qqVs < 5.4 && os == 2) {
        qq = 1;
      } else {
        // alert("请用手机QQ浏览器打开本页面");
      }
    }



    var script = document.createElement('script');
    script.src = (+qq === 1) ? '//3gimg.qq.com/html5/js/qb.js' : '//jsapi.qq.com/get?api=app.share';
    script.onload = function() {
      // cb && cb();
    };
    document.body.appendChild(script);


  }
  function getVal(id)
  {
    return document.getElementById(id).value;
  }
  function getValues()
  {
    var sharInfo = {
      url: getVal('url'),
      title: getVal('title'),
      description: getVal('description'),
      img_url: getVal('img_url')
    }
  }
  function shareFriend() {
    var shareInfo = {
      'url': getVal('url'),
      'title': getVal('title'),
      'description': getVal('description'),
      'img_url': getVal('img_url'),
      'img_title': '',
      'to_app': 1,
      'cus_txt': ''
    };
    setShare(shareInfo);
  }

  function shareTimeline() {
    var shareInfo = {
      'url': getVal('url'),
      'title': getVal('title'),
      'description': getVal('description'),
      'img_url': getVal('img_url'),
      'img_title': '',
      'to_app': 8,
      'cus_txt': ''
    };
    setShare(shareInfo);
  }

  function setShare(share) {
    if (window.browser) {
      browser.app && browser.app.share(share);
    } else if (window.qb) {
      qb.share && qb.share(share);
    }
  }

  </script>
</body>

</html>
